/**
 * 
 * 发票查询
 */
import React from 'react'
import { Table, Form, Row, Col, Select, Card, Input, Button, Modal, message, Divider, Checkbox, Spin } from 'antd'
import { $http } from 'containers/config/https';
import moment from 'moment';
import PayMentRecordModal from './component/PayMentRecordModal.jsx'
import CommonPagination from 'components/pagination/index';
import RangeDatePicker from 'components/rangePicker/index';
import IframeModal from 'pages/common/IframeModal';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import $ from 'pages/workstation/component/js/jquery-3.2.1.min.js';
import Search from 'antd/lib/input/Search';
import store from 'store';
import './style/style.less'
import ReadCard from 'components/readcard/ReadCard';
import { $loadTemplate } from '../../lodop/Common/Print.js';
import { Util } from 'tools/index';

const dateFormat = 'YYYY-MM-DD'
const { Option } = Select;


class InquiryInvoicePage extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            data: [],
            cardTypeData: [], // 卡类型
            RefundPayWayArr: [],
            user: [],
            InvStatusArr: [],
            AdmReasonArr: [],
            userData: userData,
            PatientSourceArr: [],
            visible: false,
            userInfo: {},
            total: 0,
            page: 1,
            pageSize: 50,
            showLoading: true,
            startDate: moment(new Date, dateFormat),  // //开始日期
            stopDate: moment(new Date, dateFormat),  // //结束日期
            widthTotal: 0,//宽
            languageTable1: {}, // 国际化Table1
            languageTable2: {}, // 国际化Table2
            languageData: {}, // 国际化语言包
            language: {},   // 国际化语言
            languageCode: JSON.parse(window.sessionStorage.userData).language, // 国际化语言标识
            columns: [],
            selectedRows: [],
            compleRecordIDinfo: '',
            diseascType: [],
            printAmtLoading: false,
        }
    }

    //初始化数据
    componentDidMount() {
        this.loadPatientSource()
        this.loadPatientType()
        this.tableList();
        this.cardTypeList()
        this.getPayWayData()
        this.getUserData()
        this.getInvStatusData()
        this.getAdmReasonData()
        this.handleQuery()
        this.loadDepartMent()
        this.loadDoctorId()
        this.loadUnawares()
        this.loadPiseascType()
        this.loadDoctorType()//就诊类型
        document.querySelector('.ant-table-body').style.height = store.getState().tableHeight.y + 145 + 'px';
    }

    //render 自定义项目名称
    listAdd = (i, j, languageCode) => {
        let { columns } = this.state
        columns.splice(i, j,
            {
                title: languageCode === 'CN' ? "操作" : 'Operation',
                key: 'op',
                align: "center",
                width: '230px',
                fixed: 'right',
                render: (text, record) => (
                    record.invPrintFlag && record.invPrintFlag == 'Y'
                        ? <span>
                            <span style={{ color: '#1890ff', cursor: 'pointer' }} onClick={() => { this.handlePrintInnerTnv(record) }}>打印发票</span>
                            <Divider type="vertical" />
                            {record.invNo&&record.statusCode == 'N' ? <span style={{ color: '#1890ff', cursor: 'pointer' }} onClick={this.handlePrintAmt.bind(this, record)}>作废发票</span> : null}
                            </span>

                        : <span>
                            {
                                record.statusCode == 'N' ?
                                    <span className='span' style={{ cursor: 'pointer' }} onClick={this.handlePrintAmt.bind(this, record)}>{languageCode === 'CN' ? "作废发票" : 'Print'}</span> :
                                    <span style={{ color: '#999999' }}>{languageCode === 'CN' ? "作废发票" : 'Print'}</span>
                            }
                            <Divider type="vertical" />
                            {record.invNo ? <span style={{ color: '#1890ff', cursor: 'pointer' }} onClick={this.handlePrintInv.bind(this, record)}>打印发票</span> : null}
                            <Divider type="vertical" />
                            {record.invNo ? <span style={{ color: '#1890ff', cursor: 'pointer' }} onClick={this.PrintInvoice.bind(this, record)}>补打发票</span> : null}
                        </span>
                )
            },
        )
    }

    // 院内打印--获取打印参数
    handlePrintInnerTnv = (record) => {
        let data = {
            params: [{
                "recordinvID": record.invID
            }]
        }
        $http.post('urls', this, {
            code: '05210094',
            data: data,
            success: function (res) {
                console.log(res)
                console.log(res.template)
                if (+res.errorCode === 0) {
                    $loadTemplate(res.result[0].template, res.result[0].printStr);
                }
            }
        })
    }

    //	发票遗失证明打印
    PrintInvoice = (val) => {
        let data = {}
        data = {
            params: [{
                "invID": val.invID
            }]
        }
        $http.post('urls', this, {
            code: '05210091',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    $loadTemplate(res.template, res.result);
                }
            }
        })
    }
    handlePrintInv(source) {
        let that = this
        if (that.state.userData && that.state.userData.hospCode === "H19") {
            source && source.invoiceFileUrl ? window.open(source.invoiceFileUrl) : "";
        } else if (source && source.invoiceFileUrl) {
            // window.open(source.invoiceFileUrl)
            this.iframeRef && this.iframeRef.modifyVisible(true, source.invoiceFileUrl)
        } else {
            var data = {
                'fpzl': 2,
                'fphm': source.invNo,//金税发票号码
                'fpdm': source.invCode,//金税发票代码
                'showPrintDlg': 0
            }
            var source = encodeURIComponent(JSON.stringify(data))
            var dllInput = 'SID=2\&\&\&\SIDParam=' + source//JSON.stringify({ "SID": "0", "SIDParam": source })
            if (typeof (CefSharp) != "undefined") {   // 新元素定制浏览器
                // dllInput.path = "1";
                CefSharp.BindObjectAsync("xysCefToJavaScripts");
                setTimeout(() => {
                    xysCefToJavaScripts.driveLocalHardware(JSON.stringify({ 'inputDir': 'JSInv/prykjsapplication.dll', 'clsName': 'prykjsapplication.JSHelper', 'funcName': 'GetJSData', 'dllInput': dllInput })).then((returnVale) => {
                        var res = JSON.parse(returnVale);
                        if (res.resultCode == '0') {
                            message.success('打印成功！')
                            // that.loadGoldTaxMessage()
                        }
                    })
                }, 100);
            } else {
                $.getJSON("http://127.0.0.1:62534/XYSWCFService/DynamicLoadingDLL?JsonCallback=?", {
                    input: JSON.stringify({ 'inputDir': 'JSInv/prykjsapplication.dll', 'clsName': 'prykjsapplication.JSHelper', 'funcName': 'GetJSData', 'dllInput': dllInput })
                },
                    function (data) {
                        var res = JSON.parse(data);
                        if (res.resultCode == '0') {
                            message.success('打印成功！')
                            // that.loadGoldTaxMessage()
                        }
                        // alert(vData);
                    });
            }
        }
    }

    loadDoctorType() {
        var params = {
            params: [{
                hospID: this.state.userData.hospID
            }]
        }
        $http.post('urlADS', this, {
            code: "03050088",
            data: params,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode == '0') {
                    this.setState({
                        doctorType: res.result.Data
                    })
                }
            }
        });
    }

    //打印负凭条
    handlePrintAmt = Util.debounce((data) => {
        if (this.state.printAmtLoading) return;
        this.setState({ printAmtLoading: true });
        var ipConfig = React.$getSessionData('ipConfig');
        var params = {
            params: [{
                invID: data.invID,
                invoiceNum: data.invNo, // 发票号码
                invoiceCode: data.invCode, // 发票代码
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                hospID: this.state.userData.hospID,
                groupID: this.state.userData.hospID,
                ip: ipConfig?.ipv4 || ''
            }]
        }
        $http.post('urlADS', this, {
            code: "05100363",
            data: params,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    this.setState({
                        fpSource: data,
                        printAmtLoading: false
                    }, () => {
                        message.success('作废成功');
                        // hospCode 等于 "H19" 为长存   H03为合肥
                        /*
                        if (this.state.userData && this.state.userData.hospCode !== "H19") {
                            this.handleDelPrint();
                        } else {
                            message.success('作废成功');
                        }
                        */
                        this.handleQuery();
                    })
                } else {
                    this.setState({ printAmtLoading: false });
                }
            },
            error: function () {
                this.setState({ printAmtLoading: false });
            }
        });
    })

    handleDelPrint() {
        let that = this
        var data = {
            'fpzl': 2,
            'fphm': this.state.fpSource ? this.state.fpSource.invNo : '',//金税发票号码
            'fpdm': this.state.fpSource ? this.state.fpSource.invCode : '',//金税发票代码
        }
        var source = encodeURIComponent(JSON.stringify(data))
        var dllInput = 'SID=4\&\&\&\SIDParam=' + source//JSON.stringify({ "SID": "0", "SIDParam": source })
        if (typeof (CefSharp) != "undefined") {   // 新元素定制浏览器
            // dllInput.path = "1";
            CefSharp.BindObjectAsync("xysCefToJavaScripts");
            setTimeout(() => {
                xysCefToJavaScripts.driveLocalHardware(JSON.stringify({ 'inputDir': 'JSInv/prykjsapplication.dll', 'clsName': 'prykjsapplication.JSHelper', 'funcName': 'GetJSData', 'dllInput': dllInput })).then((returnVale) => {
                    var res = JSON.parse(returnVale);
                    if (res.resultCode == '0') {
                        message.success('作废成功！')
                    }
                })
            }, 100);
        } else {
            $.getJSON("http://127.0.0.1:62534/XYSWCFService/DynamicLoadingDLL?JsonCallback=?", {
                input: JSON.stringify({ 'inputDir': 'JSInv/prykjsapplication.dll', 'clsName': 'prykjsapplication.JSHelper', 'funcName': 'GetJSData', 'dllInput': dllInput })
            },
                function (data) {
                    var res = JSON.parse(data);
                    if (res.resultCode == '0') {
                        message.success('作废成功！')
                    }
                    // alert(vData);
                });
        }
    }

    handlePrint(data) {
        var params = {
            params: [{
                recordID: data.ID,
            }]
        }
        $http.post('urlADS', this, {
            code: "05210076",
            data: params,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    message.success('打印成功')
                    let dataArr = res.result
                    dataArr && dataArr.map((item, i) => {
                        $loadTemplate(item.template, item.printStr);
                    })
                }
            }
        });
    }

    onColumnRef = (ref) => {
        this.columnRef = ref;
    }
    // 获取主列表columns
    tableList = () => {
        var data = {
            params: [{
                "reactCode": ["PayMentRecord"],
                "compontName": "InquiryInvoicePage",
                "type": "C"
            }]
        }
        $http.post('urlS', this, {
            code: '01040073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let resC = res.result.C
                    let { languageCode } = this.state
                    for (var i = 0; i < resC.length; i++) {
                        resC[i].key = i;
                    }
                    if (languageCode === "EN") {
                        resC.map((item, i) => {
                            item.title = item.enDescripts
                        })
                    }

                    if (languageCode === "CN") {
                        resC.map((item, i) => {
                            item.title = item.descripts
                        })
                    }
                    let arr = res.result && resC.length > 0 ? JSON.parse(JSON.stringify(resC)).map(item => {
                        return {
                            align: item.align,
                            widthNum: parseInt(item.width),
                            fixed: item.fixed,
                            width: item.width,
                            dataIndex: item.dataIndex,
                            title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{item.title}</div>,
                            display: item.display,
                            key: item.seqNo
                        }
                    }) : '';
                    let filterArr = arr.filter(function (item) { return item.display === 'Y' });
                    this.setState({
                        columns: filterArr,
                        languageTable1: res.result.B || {},  // 国际化Table1
                        languageTable2: res.result.C || {},  // 国际化Table2
                        languageData: res.result.language || {},  // 国际化语言包
                        widthTotal: res.totalWidth
                    }, () => {
                        this.LanCNEN(this.state.languageCode)
                        this.listAdd(filterArr.length + 1, 0, languageCode);
                    })
                }
            }
        })
    }

    LanCNEN = (code) => {
        let { languageData } = this.state
        this.setState({
            language: languageData[code]
        })
    }

    // 页码改变的回调，参数是改变后的页码及每页条数
    appPageChange = (page, pageSize) => {
        this.setState({
            page: page,
            pageSize: pageSize,
        }, () => {
            // 重新调用查询方法
            this.handleQuery();
        });
    }

    // 条数改变的回调
    apponShowSizeChange = (current, size) => {
        this.setState({
            page: current,
            pageSize: size,
        }, () => {
            // 重新调用查询方法
            this.handleQuery();
        });
    }

    startChange(date) {
        this.setState({
            startDate: date ? moment(date).format('YYYY-MM-DD') : '',
        })
    }

    endChange(date) {
        this.setState({
            stopDate: date ? moment(date).format('YYYY-MM-DD') : '',
        })
    }


    //列表数据
    handleQuery = () => {
        let { startDate, stopDate } = this.state
        if ((startDate === '' || !startDate) || (stopDate === '' || !stopDate)) {
            message.warn(this.state.languageCode === "CN" ? "请选择时间" : 'Please select time')
            return false
        }
        let { page, pageSize } = this.state;
        let { validateFields } = this.props.form;
        validateFields({ force: true }, (err, params) => {
            if (err) {
                return;
            }
            let data = {}
            params.hospID = this.state.userData.hospID,
                params.startDate = startDate || moment(new Date).format('YYYY-MM-DD')
            params.endDate = stopDate ? moment(stopDate).format('YYYY-MM-DD') : moment(new Date).format('YYYY-MM-DD')
            data = {
                params: [params],
                pagination: [{
                    pageSize: pageSize,
                    currentPage: page,
                    sortColumn: 'code',
                    sortOrder: 'asc'
                }]
            }
            $http.post('urls', this, {
                code: '05100362',
                data: data,
                success: function (res) {
                    if (res.errorCode == '0') {
                        if (res.result && res.result.data) {
                            for (var i = 0; i < res.result.data.length; i++) {
                                res.result.data[i].key = i;
                            }
                        }
                        this.setState({ data: res.result.data, total: res.result.totalCount, loading: false })
                    } else {
                        this.setState({ data: [], total: 0, loading: false })
                        message.error(res.errorMessage);
                    }
                }
            })
        })
    }
    //获取科室
    loadDepartMent() {
        var params = {
            params: [{
                hospID: JSON.parse(window.sessionStorage.userData).hospID
            }]
        }
        $http.post('urlDeault', this, {
            code: "01050029",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        departMentData: res.result.Data
                    })
                }
            }
        });
    }

    //获取挂号医生信息
    loadDoctorId() {
        var params = {
            params: [{
                locID: this.state.locId ? this.state.locId : JSON.parse(window.sessionStorage.userData).locID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03020058",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        depDoctorData: res.Data
                    })
                }
            }
        });
    }

    //获取接待人
    loadUnawares() {
        var params = {
            params: [{}]
        }
        $http.post('urlDeault', this, {
            code: "03040036",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        unawaresList: res.result,
                    })
                }
            }
        });
    }

    //获取来源渠道
    loadPatientSource() {
        var params = {
            params: [{}]
        }
        $http.post('urlDeault', this, {
            code: "05100285",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        PatientSourceArr: res.PatientSourceArr,
                    })
                }
            }
        });
    }

    //获取病人类型
    loadPatientType() {
        var params = {
            params: [{
                "hospID": JSON.parse(window.sessionStorage.userData).hospID, //医院id 
            }]
        }
        $http.post('urlDeault', this, {
            code: "05100130",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        PatientType: res.data,
                    })
                }
            }
        });
    }
    //获取病种
    loadPiseascType() {
        var params = {
            params: [{

            }]
        }
        $http.post('urlDeault', this, {
            code: "05100357",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        diseascType: res.data,
                    })
                }
            }
        });
    }
    //操作员
    getUserData = () => {
        var data = {
            params: [{
                "hospID": JSON.parse(window.sessionStorage.userData).hospID, //医院id 
                "locTypeCode": "C"
            }]
        }
        $http.post("urlS", this, {
            code: '05210023',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.user) {
                    for (var i = 0; i < res.user.length; i++) {
                        this.state.user.push(<Option value={String(res.user[i].id)} key={i + "U"}>{res.user[i].descripts}</Option>)
                    }
                    this.setState({ user: this.state.user })
                }
            },
            error: function (err) {
                this.setState({ errMsg: this.state.languageCode === "CN" ? "数据加载失败，请重试！" : 'Data loading failed, please try again' })
            }
        })
    }

    //卡类型
    cardTypeList = () => {
        var data = {
            params: [{
                hospID: JSON.parse(window.sessionStorage.userData).hospID, //医院id 
            }]
        }

        $http.post('urlS', this, {
            code: "01040059",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    let cardDeffault = res.cardType.filter((item) => {
                        return item.defaultFlag === 'Y';
                    })
                    this.setState({
                        cardType: cardDeffault[0].id, // 默认卡
                        cardTypeData: res.cardType,  // 用户数据
                    });
                }
            }
        });
    }
    //支付方式
    getPayWayData = () => {
        $http.post("urlS", this, {
            code: '05100078',
            data: { params: [] },
            success: function (res) {
                if (+res.errorCode === 0 && res.RefundPayWayArr) {
                    for (var i = 0; i < res.RefundPayWayArr.length; i++) {
                        this.state.RefundPayWayArr.push(<Option value={String(res.RefundPayWayArr[i].ID)} title='UnitID' key={i + "W"}>{res.RefundPayWayArr[i].Descripts}</Option>)
                    }
                    this.setState({ RefundPayWayArr: this.state.RefundPayWayArr })
                }
            },
            error: function (err) {
                this.setState({ errMsg: this.state.languageCode === "CN" ? "数据加载失败，请重试！" : 'Data loading failed, please try again' });
            }
        });
    }

    //收费状态
    getInvStatusData = () => {
        $http.post("urlS", this, {
            code: '05100097',
            data: { params: [] },
            success: function (res) {
                if (+res.errorCode === 0 && res.InvStatusArr) {
                    for (var i = 0; i < res.InvStatusArr.length; i++) {
                        this.state.InvStatusArr.push(<Option value={String(res.InvStatusArr[i].ID)} key={i + "S"}>{res.InvStatusArr[i].Descripts}</Option>)
                    }
                    this.setState({ InvStatusArr: this.state.InvStatusArr })
                }
            },
            error: function (err) {
                this.setState({ errMsg: this.state.languageCode === "CN" ? "数据加载失败，请重试！" : 'Data loading failed, please try again' })
            }
        })
    }
    //结算类型
    getAdmReasonData = () => {
        var data = {
            params: [{
                hospID: JSON.parse(window.sessionStorage.userData).hospID, //医院id 
            }]
        }
        $http.post("urlS", this, {
            code: '05100129',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.data) {
                    for (var i = 0; i < res.data.length; i++) {
                        this.state.AdmReasonArr.push(<Option value={String(res.data[i].id)} key={i + "A"}>{res.data[i].descripts}</Option>)
                    }
                    this.setState({ AdmReasonArr: this.state.AdmReasonArr })
                }
            },
            error: function (err) {
                this.setState({ errMsg: this.state.languageCode === "CN" ? "数据加载失败，请重试！" : 'Data loading failed, please try again' })
            }
        })
    }


    // 编辑
    handleModal(record) {
        // 初始化数据
        this.setState({ userInfo: record, visible: true, });
    }

    // 调用子组件的连接事件
    onRef = (ref) => {
        this.child = ref
    }

    // 取消
    handleCancel = () => {
        this.setState({
            visible: false,
        })
    }
    // 分页总条数
    showTotal(total) {
        return this.state.languageCode === "CN" ? `共 ${total} 条` : `Total ${total} data`;
    }

    // 页码改变的回调，参数是改变后的页码及每页条
    onChange = (page, pageSize) => {
        this.setState({ page: page, pageSize: pageSize }, () => {
            this.handleQuery()
        });
    }
    // 条数改变的回调
    onShowSizeChange = (current, size) => {
        this.setState({ page: current, pageSize: size }, () => {
            // 重新调用查询方法
            this.onChange(current, size);
        })
    }

    PrintXYPrescButtom = () => {
        if (this.state.selectedRows.length > 0) {
            for (var i = 0; i < this.state.selectedRows.length; i++) {
                this.PrintXYPresc(this.state.selectedRows[i]);
            }
        } else {
            message.error('请选择打印数据')
        }

    }

    // 回车查询
    patNodownE = (e) => {
        if (e.keyCode === 13) {
            this.handleQuery()
        }
    }
    //打印清单
    PrintXYPresc = (val) => {
        let { userInfo } = this.state
        let data = {}
        data = {
            params: [{
                "invrecordID": val.ID || userInfo.ID,
                "invrecordType": val.invType || userInfo.invType,
                "invNo": val.invNo || userInfo.invNo,
                "recordPatNum": val.recordPatNum || userInfo.recordPatNum,
                "name": val.name || userInfo.name,
                "sex": val.sexDesc || userInfo.sexDesc,
                "recordPayDate": val.recordPayDate || userInfo.recordPayDate,
                "hospID": JSON.parse(window.sessionStorage.userData).hospID
            }]
        }
        $http.post('urls', this, {
            code: '05100343',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    window.open(res.result);
                }
            }
        })
    }
    //数据导出
    DataoutputPresc = () => {
        let Formlist = this.props.form;
        window.open("http://192.168.5.36:18080/demo/reportJsp/showReport.jsp?rpx=ChargeDetails.rpx&cardTypeID=" + (Formlist.getFieldValue("cardTypeID") || '') + "&cardNo=" + (Formlist.getFieldValue("cardNo") || ' ') + "&sessionHospID=" + JSON.parse(window.sessionStorage.userData).hospID + "&recordPatNum=" + (Formlist.getFieldValue("recordPatNum") || '') + "&recordUserID=" + (Formlist.getFieldValue("recordUserID") || '') + "&invNo=" + (Formlist.getFieldValue("invNo") || '') + "&startDate=" + moment(this.state.StartDateTop).format(dateFormat) + "&endDate=" + moment(this.state.EndDateTop).format(dateFormat) + "&recordAdmReasonID=" + (Formlist.getFieldValue("recordAdmReasonID") || '') + "&payWayID=" + (Formlist.getFieldValue("payWayID") || '') + "&recordStatusID=" + (Formlist.getFieldValue("recordStatusID") || '') + "&locID=" + (Formlist.getFieldValue("locID") || '') + "&doctorID=" + (Formlist.getFieldValue("doctorID") || '') + "&deskClerkID=" + (Formlist.getFieldValue("deskClerkID") || '') + "&patTypeID=" + (Formlist.getFieldValue("patTypeID") || ''))
    }
    // 读卡 --- 根据卡号取病人信息
    handleReadCard = (value, event) => {
        if (event.keyCode) {
            this.handleQuery(); // 重新调用查询接口
            return false
        }
        let { cardType } = this.state;
        this.readCard.ReadCard(cardType, "R", (json) => {
            let patNo = json && json.patInfo ? json.patInfo.patNo : ''
            this.setState({ patNo, cardNo: json.cardNo }, () => {
                this.handleQuery(); // 重新调用查询接口
            })
        })
    }

    // //点击行，渲染当前行样式 
    // setRowClassName = (record) => {
    //     var id = ''
    //     var { selectedRowKeys } = this.state;
    //     if (selectedRowKeys) {
    //         for (var i = 0; i < selectedRowKeys.length; i++) {
    //             if (selectedRowKeys[i] == record.id) {
    //                 id = selectedRowKeys[i]
    //             }
    //         }
    //     }
    //     return record.id === id ? 'clickRowStyle' : '';
    // }

    selectRowKeys(selectedRowKeys, selectedRows) {
        this.setState({
            selectedRowKeys: selectedRowKeys,
            selectedRows: selectedRows
        })
    }

    changeDepartMent(e) {
        var id = '';
        if (e) {
            id = e.substring(e.indexOf('^') + 1)
        }
        this.setState({
            locId: id,
        }, () => {
            this.loadDoctorId();
        })
    }
    //点击行，渲染当前行样式
    onClickRow = (record) => {
        return {
            onDoubleClick: () => {
                this.setState({
                    payID: record.ID
                }, () => {
                    // this.columnRef.onOpenModel()
                    this.handleModal(record)
                });
            }
        };
    }
    //点击行，渲染当前行样式 
    setRowClassName = (record) => {
        return record.key === this.state.payID ? 'clickRowStyle' : '';
    }

    // 打印
    print = () => {
        let { selectedRows } = this.state
        let recordIDStr = ''
        selectedRows.map((item) => {
            recordIDStr += item.ID + '^'
        })
        recordIDStr = recordIDStr.substring(0, recordIDStr.length - 1);
        var data = {
            params: [{
                "hospID": JSON.parse(window.sessionStorage.userData).hospID, //医院id 
                "groupID": JSON.parse(window.sessionStorage.userData).groupID,  //角色id
                "printType": "O",
                "printTemplateCode": "GuidePatDocuments",
                "recordIDStr": recordIDStr || '',
                "invIDStr": '',

            }]
        }
        /*  */

        $http.post('urlADS', this, {
            code: "05100153",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    let dataArr = res.data
                    let template = res.template
                    dataArr.map((item, i) => {
                        $loadTemplate(template[i], item.toString());
                    })
                }
            }
        });
    }


    render() {
        let { language, widthTotal, printAmtLoading } = this.state
        let { getFieldDecorator } = this.props.form;
        //卡类型
        var cardTypeOPtion = []
        this.state.cardTypeData && this.state.cardTypeData.map((item, index) => {
            cardTypeOPtion.push(
                <Option title={item.descripts + '^' + item.descriptsSPCode} key={index} value={item.id}>{item.descripts}</Option>
            )
        })
        //获取科室信息
        let departMentOption = []
        this.state.departMentData && this.state.departMentData.map((item, index) => {
            departMentOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
        })

        //获取科室医生信息
        let depDoctorOption = []
        this.state.depDoctorData && this.state.depDoctorData.map((item, index) => {
            depDoctorOption.push(<Option key={index} value={item.doctorID}>{item.descripts}</Option>)
        })

        //接待人
        let unawaresListOption = []
        this.state.unawaresList && this.state.unawaresList.map((item, index) => {
            unawaresListOption.push(<Option key={index} value={item.id} code={item.descripts} name={item.descriptsSPCode}>{item.descripts}</Option>)
        })
        //病种
        let diseascListOption = []
        this.state.diseascType && this.state.diseascType.map(item => {
            diseascListOption.push(<Option key={item.id} value={item.id}>{item.descripts}</Option>)
        })

        //病人类型
        let PatientTypeOption = []
        this.state.PatientType && this.state.PatientType.map(item => {
            PatientTypeOption.push(<Option key={item.id} value={item.id}>{item.descripts}</Option>)
        })

        //来源渠道
        let PatientSourceOption = []
        this.state.PatientSourceArr && this.state.PatientSourceArr.map(item => {
            PatientSourceOption.push(<Option key={item.id} value={item.id}>{item.descripts}</Option>)
        })

        //就诊类型
        let doctorTypeOption = []
        this.state.doctorType && this.state.doctorType.map((item, index) => {
            doctorTypeOption.push(<Option key={index} value={item.admTypeID}>{item.admDesc}</Option>)
        })

        const rowSelection = {
            onChange: (selectedRowKeys, selectedRows) => {
                this.setState({ selectedRows })
            },
            getCheckboxProps: record => ({
                disabled: (record.ID === '' ? true : false),
            }),
        };

        const formItemInput = {
            labelCol: { span: 8 },
            wrapperCol: { span: 16 }
        };
        return (
            <Spin spinning={printAmtLoading} tip="发票作废中，请耐心等待…">
                <div className='readCard-body' style={{ width: '100%', height: '100%', background: '#F5F7FE' }} id='read-card-body'>
                    <ReadCard ref={r => this.readCard = r} />
                    <Card style={{ float: 'left', width: '20%', height: store.getState().tableHeight.y + 242 }}>
                        <Form>
                            <Form.Item {...formItemInput} label={language.PayMentRecordcardType && language.PayMentRecordcardType.descripts}>
                                {getFieldDecorator("cardTypeID", {
                                    initialValue: this.state.cardType
                                })(
                                    <Select style={{ width: '100%' }}>
                                        {cardTypeOPtion}
                                    </Select>
                                )}
                            </Form.Item>

                            <Col span={25}>
                                <Form.Item>
                                    {getFieldDecorator("cardNo", {
                                        rules: [{ required: false }]
                                    })(
                                        <Search
                                            // onKeyUp={(e) => { this.patNodownE(e) }}
                                            style={{ width: '100%' }}
                                            placeholder={language.PayMentRecordpatientCardNumber && language.PayMentRecordpatientCardNumber.message}
                                            enterButton={language.PayMentRecordreadcard && language.PayMentRecordreadcard.descripts}
                                            onSearch={this.handleReadCard}
                                        />
                                    )}
                                </Form.Item>
                            </Col>

                            <Form.Item {...formItemInput} label={<span className='common-label-style'>{language.PayMentRecordIDNCM && language.PayMentRecordIDNCM.descripts}</span>}>
                                {getFieldDecorator("number", {
                                    rules: [{ required: false }]
                                })(
                                    <Input style={{ width: '100%' }} placeholder={language.PayMentRecordIDNCM && language.PayMentRecordIDNCM.message} onKeyUp={(e) => { this.patNodownE(e) }} />
                                )}
                            </Form.Item>

                            <Form.Item {...formItemInput} label={<span className='common-label-style'>{language.PayMentRecordchargeDate && language.PayMentRecordchargeDate.descripts}</span>}>
                                <span style={{ display: 'inline-block', verticalAlign: 'middle' }}><RangeDatePicker format='YYYY-MM-DD' width={'100%'}
                                    startDate={this.state.startDate} endDate={this.state.stopDate}
                                    startChange={this.startChange.bind(this)} endChange={this.endChange.bind(this)} />
                                </span>
                            </Form.Item>

                            <Form.Item {...formItemInput} label={<span className='common-label-style'>{language.PayMentRecordinvoiceAndRefund && language.PayMentRecordinvoiceAndRefund.descripts}</span>}>
                                {getFieldDecorator("invNo", {
                                    rules: [{ required: false }]
                                })(
                                    <Input style={{ width: '100%' }} placeholder={language.PayMentRecordinvoiceAndRefund && language.PayMentRecordinvoiceAndRefund.message} onPressEnter={() => { this.setState({ page: 1, pageSize: '50' }, () => { this.handleQuery() }) }} />
                                )}
                            </Form.Item>

                            <Form.Item {...formItemInput} label={<span className='common-label-style'>{language.PayMentRecordoperator && language.PayMentRecordoperator.descripts}</span>}>
                                {getFieldDecorator("printUserID", {
                                    rules: [{ required: false }]
                                })(
                                    <Select style={{ width: '100%' }} placeholder={language.PayMentRecordoperator && language.PayMentRecordoperator.message} allowClear>
                                        {this.state.user}
                                    </Select>
                                )}
                            </Form.Item>

                            <Form.Item {...formItemInput} label={<span className='common-label-style'>{language.PayMentRecordchargeState && language.PayMentRecordchargeState.descripts}</span>}>
                                {getFieldDecorator("statusID", {
                                    rules: [{ required: false }]
                                })(
                                    <Select style={{ width: '100%' }} placeholder={language.PayMentRecordchargeState && language.PayMentRecordchargeState.message} allowClear>
                                        {this.state.InvStatusArr}
                                    </Select>
                                )}
                            </Form.Item>
                            <Form.Item {...formItemInput} label={<span className='common-label-style'>{'就诊类型'}</span>}>
                                {getFieldDecorator("admTypeID", {
                                    rules: [{ required: false }]
                                })(
                                    <Select style={{ width: '100%' }} placeholder={'请选择就诊类型'} allowClear>
                                        {doctorTypeOption}
                                    </Select>
                                )}
                            </Form.Item>

                            {/* <Form.Item {...formItemInput} className='checkbox' label={<span className='common-label-style '>{language.PayMentRecordPrintFlag && language.PayMentRecordPrintFlag.descripts}</span>}>
                            {getFieldDecorator('printFlag', {
                                initialValue: true,
                                valuePropName: 'checked',
                            })(
                                <Checkbox></Checkbox>
                            )}
                        </Form.Item> */}
                            <Col span={25}>
                                {/* <Button onClick={() => { this.print() }} style={{ width: '48%' }}>打印导诊单</Button> */}

                                <Button type="primary" style={{ width: '90%', marginLeft: 10 }}
                                    onClick={() => { this.setState({ page: 1, pageSize: '50' }, () => { this.handleQuery() }) }}>{language.PayMentRecordquery && language.PayMentRecordquery.descripts}</Button>

                            </Col>
                        </Form>
                    </Card>
                    <Card style={{ float: 'right', width: '79.5%', height: store.getState().tableHeight.y + 242 }}>
                        <Table
                            dataSource={this.state.data}
                            columns={this.state.columns}
                            // className='TableA'
                            // rowClassName={this.setRowClassName}
                            pagination={false}
                            scroll={{ x: (this.state.columns && this.state.columns.length > 0 ? widthTotal : 2900), y: store.getState().tableHeight.y + 145 }}
                            bordered
                            rowKey={(data) => {
                                return data.key
                            }}
                            loading={this.state.loading}
                        // rowSelection={rowSelection}
                        // onRow={this.onClickRow}
                        />
                        <CommonPagination size="large" current={this.state.page} total={this.state.total} search='search'
                            onShowSizeChange={this.apponShowSizeChange} complete={true} dataSource={this.state.data}
                            onChange={this.appPageChange} />
                        <ColumnAuthoritysModel
                            clientWidth='900px'
                            compontName='InquiryInvoicePage'
                            configType="C"
                            onRef={this.onColumnRef}
                            reloadData={this.tableList}
                        />
                    </Card>
                    <div>
                        <Modal
                            visible={this.state.visible}
                            okText={this.state.languageCode === "CN" ? "确定" : 'Set'}
                            onOk={this.handleCancel}
                            onCancel={this.handleCancel}
                            cancelText={this.state.languageCode === "CN" ? "取消" : 'Cancel'}
                            width='1000px'
                            title={this.state.languageCode === "CN" ? "费用明细" : 'Cost Detail'}
                        >
                            <PayMentRecordModal onRef={this.onRef} userInfo={this.state.userInfo} key={this.state.userInfo.ID}></PayMentRecordModal>
                        </Modal>
                    </div>
                    <IframeModal onRef={ref => this.iframeRef = ref} />
                </div>
            </Spin>
        )
    }
}
export default Form.create()(InquiryInvoicePage)